import EventTypeEnum from '../enum/EventTypeEnum';

/*
 * @Author: jingfuu@163.com
 * @Date: 2024-12-02 16:59:36
 * @LastEditTime: 2024-12-12 16:14:36
 * @Description: 系统
 */
class BaseEvent<T> {
  private data: T;
  private type: EventTypeEnum;

  constructor(data: T, type: EventTypeEnum) {
    this.data = data;
    this.type = type;
  }

  getData() {
    return this.data;
  }

  getType() {
    return this.type;
  }

  static builder<T>() {
    return new BaseEventBuilder<T>();
  }
}

class BaseEventBuilder<T> {
  private _data: T | undefined;
  private _type: EventTypeEnum | undefined;

  data(data: T): BaseEventBuilder<T> {
    this._data = data;
    return this;
  }

  type(type: EventTypeEnum): BaseEventBuilder<T> {
    this._type = type;
    return this;
  }

  build(): BaseEvent<T> {
    if (this.data === undefined || this.type === undefined) {
      throw new Error('Data and Type must be set before building.');
    }
    return new BaseEvent(this._data, this._type);
  }
}
export default BaseEvent;
